#ifndef _SDL_EVENT_H_
#define _SDL_EVENT_H_

#include <SDL/SDL.h>
#include "sdl_exception.h"
#include "speaker.h"
#include "singleton.h"

namespace sdl {

class Event;

class EventListener {
public:
	template<int I> struct X { enum { TYPE = I }; };
	typedef X<0> NewEvent;

	virtual void on(NewEvent, const SDL_Event*) throw() { }
};


class Event
	: public Singleton<Event>
	, public Speaker<EventListener>
{
public:
	// Wait for an event to occur and notify
	// listeners about it
	void wait() throw (sdl::Exception);

	// Call this to drop out from wait()
	void stopWaiting();

	// Send a user event to event queue
	void sendUserEvent(int code, void* arg1 = NULL, void* arg2 = NULL);

private:
	Event();
    friend class Singleton;

	SDL_Event _event;
};

} // namespace sdl

#endif // _SDL_EVENT_H_

